<!--
 * @Description  : 系统用户
 * @Author       : zhao
 * @Date         : 2022-07-11 09:16:55
 * @LastEditors  : zhao
 * @LastEditTime : 2022-08-02 18:10:54
-->
<template>
	<div class="system-user-container">
		<zTable :searchType="searchType" :tableHeader="tableHeader" :tableData="tableData" :title="'管理员用户'" />
		<AddUer ref="addUserRef" />
		<EditUser ref="editUserRef" />
	</div>
</template>

<script lang="ts">
import { toRefs, reactive, onMounted, ref, defineComponent, onBeforeUnmount, watch } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import AddUer from '/@/views/system/user/component/addUser.vue';
import zTable from '/@/components/zTable/index.vue';
import EditUser from '/@/views/system/user/component/editUser.vue';
import usdata from "./user.ts"
import { useTableInfo } from '/@/stores/ztable'


export default defineComponent({
	name: 'systemUser',
	components: { AddUer, EditUser, zTable },
	setup() {
		const addUserRef = ref();
		const editUserRef = ref();
		let useTableInfos = useTableInfo()
		useTableInfos.$reset()
		let { zTable, zTableType, getTableData, zTableFunction } = useTableInfo()


		const searchType = ref(usdata.searchType);
		const tableHeader = ref(usdata.tableHeader);
		const tableData = ref(usdata.tableData);
		// 初始化表格数据
		const initTableData = async () => {

			useTableInfos.zTable.mdName.name = "useUserInfo"
			useTableInfos.zTable.mdName.url = "getSysUserInfo"
			useTableInfos.zTableFunction.add = true
			useTableInfos.zTableFunction.modify = true
			await useTableInfos.getTableData()
		};

		//打开新增页
		const add = () => {
			addUserRef.value.openDialog();
		}
		//打开详情页
		const edit = () => {
			editUserRef.value.openDialog();
		}
		watch(useTableInfos, (newVal, oldValue) => {

			if (newVal.zTableFunAddShow) add()
			if (newVal.zTableFunEditShow) edit()
		})
		// 页面加载时
		initTableData();
		onMounted(() => {
		});

		return {
			addUserRef,
			editUserRef,

			searchType,
			tableHeader,
			tableData,
		};
	},
});
</script>
